import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:my_salary/pages/statistics/bar_chart.dart';
import 'package:my_salary/pages/statistics/line_chart.dart';
import 'package:my_salary/pages/statistics/pie_chart.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class StatisticsPage extends StatefulWidget {
  const StatisticsPage({super.key});

  @override
  State<StatisticsPage> createState() => _StatisticsPageState();
}

class _StatisticsPageState extends State<StatisticsPage>
    with WidgetsBindingObserver {
  @override
  Widget build(BuildContext context) {
    final l10n = AppLocalizations.of(context)!;
    final cs = Theme.of(context).colorScheme;
    final tt = Theme.of(context).textTheme;

    return Scaffold(
      appBar: AppBar(
        title: Text(l10n.statisticsTitle, style: tt.titleLarge),
        backgroundColor: cs.surface,
        elevation: 0.5,
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          padding: EdgeInsets.all(8.w),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              _buildChartCard(context, LineChartSample1()),
              SizedBox(height: 16.h),
              Divider(color: cs.outlineVariant),
              _buildChartCard(context, BarChartSample2()),
              SizedBox(height: 16.h),
              Divider(color: cs.outlineVariant),
              _buildChartCard(context, PieChartSample3()),
            ],
          ),
        ),
      ),
    );
  }

  /// 卡片包装器
  Widget _buildChartCard(BuildContext context, Widget child) {
    return Card(
      elevation: 2,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.r),
      ),
      child: child,
    );
  }
}
